home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / gnome-power-manager-inhibit < prev    next >
Encoding:
Text File  |  2009-04-08  |  1.4 KB  |  48 lines

  1. #!/usr/bin/python
  2.  
  3. # Copyright (C) 2008 Canonical Ltd
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19. import dbus
  20. import time
  21. import os
  22. import sys
  23.  
  24. if len(sys.argv) < 2:
  25.     print "Must be called with a command"
  26.     exit(1)
  27.  
  28. session_bus = dbus.SessionBus()
  29.  
  30. if session_bus:
  31.     gpm = session_bus.get_object('org.freedesktop.PowerManagement',
  32.                                 '/org/freedesktop/PowerManagement/Inhibit')
  33. if gpm:
  34.     cookie = gpm.Inhibit("Command Line: " + sys.argv[1], "Long Execution")
  35. else:
  36.     sys.stderr.write(sys.argv[0] + ": Unable to inhibit, executing command anyway\n")
  37.  
  38. retval = 0
  39. try:
  40.     retval = os.spawnvp(os.P_WAIT, sys.argv[1], sys.argv[1:])
  41. except KeyboardInterrupt:
  42.     x = 5
  43. finally:
  44.     if gpm and cookie:
  45.         gpm.UnInhibit(cookie)
  46.  
  47. exit(retval)
  48.